const validator = require('validator');
const bcrypt = require('bcrypt');
const Sequelize = require('sequelize');
const sequelize = require('../mysql/mysql');

const User = sequelize.define('user', {
    name: {
        type: Sequelize.STRING,
        primaryKey: true,
    },
    password: {
        type: Sequelize.STRING,
    },
    age: {
        type: Sequelize.TINYINT,
    },
    sex: {
        type: Sequelize.BOOLEAN,
    },
    height: {
        type: Sequelize.TINYINT,
    },
    weight: {
        type: Sequelize.DECIMAL(3, 1),
    },
    validate:{
        type:Sequelize.BOOLEAN,
    }
});

User.prototype.validateName = function(){
    return validator.isEmail(this.name);
};

User.prototype.checkPassword = async function(pw){
    const result = await bcrypt.compare(pw,this.password);
    return result;
};

User.prototype.checkValidate = function(){
    return this.dataValues.validate;
};

User.validateName = function(name){
    return validator.isEmail(name);
};

// User.sync({force:true});

module.exports = User;
